/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.ufpa.sorteio.dao;

import br.com.ufpa.sorteio.entidade.Atividade;
import br.com.ufpa.sorteio.entidade.Professor;
import java.util.List;
import javax.persistence.Query;

/**
 *
 * @author Weslley
 */
public class ProfessorDAO extends GenericDAO<Professor> {

    public Professor autenticaProfessor(String username, String passwd) {

        Query query = getEntityManager().createQuery("SELECT p FROM " + Professor.class.getName() + " p WHERE p.username = :username AND p.passwd = :passwd");
        query.setParameter("username", username);
        query.setParameter("passwd", passwd);

        if (query.getSingleResult() == null) {
            return null;
        }

        return (Professor) query.getSingleResult();
    }
    
    public List<Atividade> listaAtividadesProfessor(Long id) {

        Query query = getEntityManager().createQuery("SELECT a FROM " + Atividade.class.getName() + " a WHERE a.professor.id = :id");
        query.setParameter("id", id);

        return query.getResultList();
    }

}
